<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>scrollWidth&Height</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
        .box{
            position: absolute;
            top: 50px;
            left: 50px;
            width: 150px;
            height: 150px;
            background-color: #f00;
        }

        .inner {
            width: 400px;
            height: 400px;
            background-color: #ff9000;
        }
    </style>
</head>
<body>
    <div class="box"></div>

    <script type="text/javascript">
        // scroll  滚动家族  scrollWidth/Height scrollTop/Left
        // elem.scrollWidth/Height  返回元素内容区大小  width/height + padding
        // 如果元素内容溢出，返回溢出内容的宽高 + padding(上左)  如果元素添加了overflow，padding（上下左）
        var box = document.querySelector(".box");

        console.log("box.scrollWidth", box.scrollWidth, "\nbox.scrollHeight", box.scrollHeight); // w150 h150
        
        box.style.padding = "30px";
        console.log("add padding", "\nbox.scrollWidth", box.scrollWidth, "\nbox.scrollHeight", box.scrollHeight);// w210 h210

        box.style.border = "30px solid #00f";
        console.log("add border", "\nbox.scrollWidth", box.scrollWidth, "\nbox.scrollHeight", box.scrollHeight);// w210 h210
        
        box.innerHTML = "<div class='inner'></div>";
        console.log("add inner", "\nbox.scrollWidth", box.scrollWidth, "\nbox.scrollHeight", box.scrollHeight);// w430 h430
        
        box.style.overflow = "scroll";
        console.log("add overflow", "\nbox.scrollWidth", box.scrollWidth, "\nbox.scrollHeight", box.scrollHeight);// w430 h460
        
        box.children[0].style.width = "400.3333333333px";
        console.log("set width .333", "\nbox.scrollWidth", box.scrollWidth, "\nbox.scrollHeight", box.scrollHeight);// w431 h460
        
        box.scrollWidth = 600;
        console.log("set scrollWidth", "\nbox.scrollWidth", box.scrollWidth, "\nbox.scrollHeight", box.scrollHeight);// w431 h460
    </script>
</body>
</html>